/* $Id: TournamentView.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package org.jugger.tournament.gui.view;

import java.awt.event.KeyEvent;

import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;

import org.jugger.tournament.model.Tournament;

import util.I18N;

/**
 * @author Sven Hamer
 */
public class TournamentView extends JTabbedPane implements TableModelListener {

	private static final long serialVersionUID = 8917051505991233198L;

	private final Tournament tournament;
	private final OverviewPanel overviewPanel;
	private final RankingsPanel rankingsPanel;
	private final RoundsPanel roundsPanel;
	private final StatisticsPanel statisticsPanel;

	public TournamentView(Tournament tournament) {
		this.tournament = tournament;

		// ImageIcon icon = createImageIcon("images/middle.gif");

		overviewPanel = new OverviewPanel(tournament);
		overviewPanel.addTableModelListener(this);
		JScrollPane overviewScrollPane = new JScrollPane(overviewPanel);
		addTab(I18N.__("currentRound"), null, overviewScrollPane, null);
		setMnemonicAt(0, KeyEvent.VK_1);

		rankingsPanel = new RankingsPanel(tournament);
		JScrollPane rankingsScrollPane = new JScrollPane(rankingsPanel);
		addTab(I18N.__("rankings"), null/* icon */, rankingsScrollPane, null);
		setMnemonicAt(1, KeyEvent.VK_2);

		roundsPanel = new RoundsPanel(tournament);
		JScrollPane roundsScrollPane = new JScrollPane(roundsPanel);
		addTab(I18N.__("matches"), null/* icon */, roundsScrollPane, null);
		setMnemonicAt(2, KeyEvent.VK_3);

		statisticsPanel = new StatisticsPanel(tournament);
		JScrollPane statisticsScrollPane = new JScrollPane(statisticsPanel);
		addTab(I18N.__("statistics"), null/* icon */,statisticsScrollPane, null);
		setMnemonicAt(3, KeyEvent.VK_4);
	}

	public void tableChanged(TableModelEvent arg0) {
		overviewPanel.reloadData(tournament);
		rankingsPanel.reloadData(tournament);
		roundsPanel.reloadData(tournament);
		statisticsPanel.reloadData(tournament);
	}
}
